package com.jhjx.wx.mp.handler;

import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.springframework.stereotype.Component;

import java.util.Map;

import static me.chanjar.weixin.common.api.WxConsts.MenuButtonType;

@Component
public class MenuHandler extends AbstractHandler {

    @Override
    public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService weixinService, WxSessionManager sessionManager) {
        String mediaId = wxMessage.getMediaId();
        if (MenuButtonType.VIEW.equals(wxMessage.getEvent())) {
            return null;
        }
        return WxMpXmlOutMessage.IMAGE().mediaId(mediaId).fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser()).build();
    }

}
